let $ = layui.jquery;

export default class AddHots {

    constructor() {
        this.render();
        this.handle();
    }
    render() {
        let template = `
        <div class="layui-form-item">
        <label class="layui-form-label">热播</label>
        <div class="layui-input-block">
            <input type="text" name="ishot" placeholder="请输入1" autocomplete="off" class="layui-input">
        </div>
    </div>
       
        <form class="layui-form" action="" method="post">
        <div class="layui-form-item">
            <label class="layui-form-label">电影名</label>
            <div class="layui-input-block">
                <input type="text" name="name" required lay-verify="required" placeholder="请输入电影名"
                    autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">电影英文名</label>
            <div class="layui-input-block">
                <input type="text" name="ename" required lay-verify="required" placeholder="请输入英文名" autocomplete="off"
                    class="layui-input">
            </div>
        </div>
    
        
    <div class="layui-form-item">
    <label class="layui-form-label">电影类型</label>
    <div class="layui-input-block">
      <input type="radio" name="type" value="动作" title="动作" checked>
      <input type="radio" name="type" value="冒险" title="冒险">
      <input type="radio" name="type" value="科幻" title="科幻">
      <input type="radio" name="type" value="犯罪" title="犯罪">
      <input type="radio" name="type" value="动画" title="动画">
      <input type="radio" name="type" value="爱情" title="爱情">
      <input type="radio" name="type" value="悬疑" title="悬疑">
    </div>
  </div>

  <div class="layui-form-item">
  <label class="layui-form-label">电影上映地区</label>
  <div class="layui-input-block">
    <input type="radio" name="area" value="中国" title="中国" checked>
    <input type="radio" name="area" value="日本" title="日本">
    <input type="radio" name="area" value="韩国" title="韩国">
    <input type="radio" name="area" value="美国" title="美国">
    <input type="radio" name="area" value="欧洲" title="欧洲">
    <input type="radio" name="area value="印度" title="印度">
    <input type="radio" name="area" value="泰国" title="泰国">
  </div>
</div>

        <div class="layui-form-item">
            <label class="layui-form-label">评分</label>
            <div class="layui-input-block">
                <input type="text" name="score" placeholder="请输入评分" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">演员</label>
            <div class="layui-input-block">
                <input type="text" name="actorName" placeholder="请输入演员" autocomplete="off" class="layui-input">
            </div>
        </div>
    
        
    
        <div class="layui-form-item">
            <label class="layui-form-label">时长</label>
            <div class="layui-input-block">
                <input type="text" name="time" placeholder="请输入时长" autocomplete="off" class="layui-input">
            </div>
        </div>
    
       
    

        <div class="layui-form-item">
            <label class="layui-form-label">票房</label>
            <div class="layui-input-block">
                <input type="text" name="count" placeholder="请输入票房" autocomplete="off" class="layui-input">
            </div>
        </div>
    
        <div class="layui-form-item">
            <label class="layui-form-label">剧情简介</label>
            <div class="layui-input-block">
                <input type="text" name="intro" placeholder="请输入剧情简介" autocomplete="off" class="layui-input">
            </div>
        </div>
    
    
        `;

        $("#uphotsTemplate").html(template);

    }
    handle() {
        let form = layui.form;
        let layer = layui.layer;
        let table = layui.table;



        layer.open({
            type: 1,
            area: ["650px", "600px"],
            content: $("#uphotsTemplate").html(),
            btn: ["添加", "取消"],
            success: function () {
                form.render();
            },

            yes: function () {
                let ishot = $("input[name='ishot']").val();
                let name = $("input[name='name']").val();
                let ename = $("input[name='ename']").val();
                let type = $("input[name='type']:checked").val();
                let area = $("input[name='area']:checked").val();
                let score = $("input[name='score']").val();
                let actorName = $("input[name='actorName']").val();
                
                let time = $("input[name='time']").val();
                
                let areas = $("input[name='area']").val();
                let count = $("input[name='count']").val();
                let intro = $("input[name='intro']").val();
                // let indexImage = $('#indexImage').attr('src');

                $.ajax({
                    type: "post",
                    url: "/api/hots/addhots",
                    data: {
                        ishot,
                        name,
                        ename,
                        type,
                        area,
                        score,
                        actorName,
                       
                        time,
                       
                        areas,
                        count,
                        intro,
                        // indexImage,
                    },


                    success: function (res) {
                        if (res.code === 200) {


                            layer.closeAll();

                            table.reload("myTable", {});

                            layer.msg("添加成功");



                        } else {
                            layer.msg("添加失败");
                        }
                    }
                })
            }
        })

    }


}